#
# @lc app=leetcode.cn id=491 lang=python
#
# [491] 非递减子序列
#

# @lc code=start
class Solution(object):
    def findSubsequences(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        self.nums = nums
        self.result = []
        self.sub = []
        self.loop(0)
        return self.result
        

    def loop(self, index):
        if len(self.sub)>1:
            self.result.append(self.sub[:])
        if index == len(self.nums):
            return

        cset = set()
        for i in range(index, len(self.nums)):
            if self.nums[i] in cset:
                continue
    
            if len(self.sub)==0 or (len(self.sub)>0 and self.nums[i] >= self.sub[-1]):
                cset.add(self.nums[i])
                self.sub.append(self.nums[i])
                self.loop(i+1)
                self.sub.pop()
        
# @lc code=end

